{%- if storeConfig.yahoo_pixel_id -%}
    <script>(function (w, d, t, r, u) {
            w[u] = w[u] || [];
            w[u].push({'projectId': '{{ storeConfig.yahoo_projectid }}', 'properties': {'pixelId': '{{ storeConfig.yahoo_pixel_id }}'}});
            var s = d.createElement(t);
            s.src = r;
            s.async = true;
            s.onload = s.onreadystatechange = function () {
                var y, rs = this.readyState, c = w[u];
                if (rs && rs != "complete" && rs != "loaded") {
                    return
                }
                try {
                    y = YAHOO.ywa.I13N.fireBeacon;
                    w[u] = [];
                    w[u].push = function (p) {
                        y([p])
                    };
                    y(c)
                } catch (e) {
                }
            };
            var scr = d.getElementsByTagName(t)[0], par = scr.parentNode;
            par.insertBefore(s, scr)
        })(window, document, "script", "https://s.yimg.com/wi/ytc.js", "dotq");</script>
<script>
    (function(){
        function triggerPixels( data) {
            window.dotq = window.dotq || [];
            window.dotq.push({
                'projectId': '{{ storeConfig.yahoo_projectid }}',
                'properties': {
                    'pixelId': '{{ storeConfig.yahoo_pixel_id }}',
                    'qstrings': data
                }
            });
        }
        window['TOP_GLOBAL_CALLBACK_LAYER'].register({
          'page_view': function() {
                {%- if template == 'blog_detail' -%}
                triggerPixels({
                    'et': 'custom',
                    'ea': '{{template}}',
                    'el': '{{blog.title | filter_string_format}}',
                    'ev': '{{blog.id}}',
                }); 
                {%- elsif template == 'page_detail' -%}
                triggerPixels({
                    'et': 'custom',
                    'ea': '{{template}}',
                    'el': '{{page.title | filter_string_format}}',
                    'ev': '{{page.id}}',
                }); 
                {%  else %}
                triggerPixels({
                    'et': 'custom',
                    'ea': '{{template}}'
                });
                {%- endif -%}
          },
          'view_category':function(collection){
                triggerPixels({
                    'et': 'custom',
                    'ea': '{{template}}',
                    'el': collection.title,
                    'ev': collection.id,
                });
          },
          'view_content': function(product) {
                triggerPixels({
                    'et': 'custom',
                    'ea': 'ViewProduct',
                    'ec': product.product_type,
                    'ev': 1,
                    'gv': product.variant.price,
                    'product_id': product.spu,
                });
          },
          'search': function(value) {
                triggerPixels({
                    'et': 'custom',
                    'ea': '{{template}}',
                    'el': value
                });
          },
          'purchase': function(order) {
                order.products.forEach(function(product) {
                    triggerPixels({
                        'et': 'custom',
                        'ea': 'Purchase',
                        'ec': product.product_type,
                        'ev': product.quantity,
                        {% if storeConfig.yahoo_sales_goods_amount %}
                        'gv': Number(order.current_subtotal_price).plus(Number(order.current_coupon_price)).plus(order.current_promotion_price),
                        {% else %}
                        'gv': order.total_price,
                        {% endif %}
                        'product_id': product.spu

                    });
                });
          },
          'begin_checkout':function(){
                triggerPixels({
                    'et': 'custom',
                    'ea': 'begin_checkout',
                });
          },
          'add_payment_information':function(){
                triggerPixels({
                    'et': 'custom',
                    'ea': 'add_payment_information',
                });
          },
          'add_shipping_information':function(){
                triggerPixels({
                    'et': 'custom',
                    'ea': 'add_shipping_information',
                });
          },
          'add_address_information':function(){
                triggerPixels({
                    'et': 'custom',
                    'ea': 'add_address_information',
                });
          },
          'add_to_cart': function(ecdata) {
                triggerPixels({
                    'et': 'custom',
                    'ea': 'AddToCart',
                    'ec': ecdata['ec_data_category'],
                    'gv': ecdata['ec_data_price']*ecdata['ec_data_quantity'],
                    'ev': ecdata['ec_data_quantity'],
                    'product_id': ecdata['ec_data_spu'],
                });
          },
          'remove_from_cart':function(ec_data){
                triggerPixels({
                    'et': 'custom',
                    'ea': 'remove_from_cart',
					'ec': ec_data['ec_data_category'],
                    'gv': ec_data['ec_data_price']*ec_data['ec_data_quantity'],
                    'ev': ec_data['ec_data_quantity'],
                    'el': ec_data['ec_data_spu'],
                });
          },
          'share_product':function(ec_data){
                triggerPixels({
                    'et': 'custom',
                    'ea': 'share_product',
					'ec': ec_data['ec_data_category'],
                    'gv': ec_data['ec_data_price']*ec_data['ec_data_quantity'],
                    'ev': ec_data['ec_data_quantity'],
                    'el': ec_data['ec_data_spu'],
                });
          },
          'add_to_wishlist': function() {
            triggerPixels({
                'et': 'custom',
                'ea': 'AddToWishlist',
            });
          },
          'sign_up': function() {
            triggerPixels({
                'et': 'custom',
                'ea': 'sign_up',
            });
          },
          'login': function() {
            triggerPixels({
                'et': 'custom',
                'ea': 'login',
            });
          },
          'generate_lead':function(){
                triggerPixels({
                    'et': 'custom',
                    'ea': 'generate_lead',
                });
          },
      });
    })();
</script>
{%- endif -%}


